/**
 * 建造者模式
 */
// 建造型模式用于创建过程稳定，但配置多变的对象。在《设计模式》一书中的定义是：将一个复杂的构建与其表示相分离，使得同样的构建过程可以创建不同的表示

// 经典的「建造者-指挥者」模式现在已经不太常用了，现在建造者模式主要用来通过链式调用生成不同的配置
class Builder1 {
    readonly type: string;
    size = '中杯';
    pearl = true;
    ice = false;
    constructor(type: string) {
        this.type = type;
    }
    setSize(size: string) {
        this.size = size;
        return this;
    }
    setPearl(pearl: boolean) {
        this.pearl = pearl;
        return this;
    }
    setIce(cold: boolean) {
        this.ice = cold;
        return this;
    }
    build(): MilkTea {
        return new MilkTea(this);
    }
}
class MilkTea {
    private readonly type: string;
    private readonly size: string;
    private readonly pearl: boolean;
    private readonly ice: boolean;
    static Builder1 = Builder1;

    constructor(builder: Builder1) {
        this.type = builder.type;
        this.size = builder.size;
        this.pearl = builder.pearl;
        this.ice = builder.ice;
    }
    public getType() {
        return this.type;
    }

    public getSize() {
        return this.size;
    }

    public isPearl() {
        return this.pearl;
    }
    public isIce() {
        return this.ice;
    }
}
const milkTea = new MilkTea.Builder1('原味').setSize('大杯').build();
console.log(milkTea);
